package com.tairan.chapter.nacos.config.controller;

import com.tairan.chapter.nacos.config.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/config")
//@RefreshScope
@EnableConfigurationProperties(User.class)
public class ConfigController {

    @Value("${tairan.name:}")
    private String name;

    @Value(value = "${tairan.age:}")
    private String age;

    @Value(value = "${tairan.like:}")
    private String like;

    @Autowired
    private User user;

    @RequestMapping("/get")
    public String get() {
        return String.format("配置信息，名称：%s，年龄：%s，爱好：%s", name, age, like);
    }

    @RequestMapping("/user")
    public User getUser() {
        return user;
    }

}
